<?php

declare(strict_types=1);

namespace Plugin\Attractions\AttractionManagement\Controller;

use Common\CommonController;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\Swagger\Annotation\HyperfServer;
use Plugin\Attractions\AttractionManagement\Service\AttractionService;

#[HyperfServer(name: 'http')]
#[Controller('attractions/attraction-management')]
class AttractionController extends CommonController
{ 
    #[Inject]
    private AttractionService $service;

    #[GetMapping('listAttractions')]
    public function listAttractions()
    {
        $data = $this->valid([
            'id' => 'integer',
            'name' => 'string',
            'introTitle' => 'string',
            'intro' => 'string',
            'address' => 'string',
            'phone' => 'string',
            'openTime' => 'string',
            'closeTime' => 'string',
            'status' => 'integer',
            'page' => 'integer|min:1',
            'pageSize' => 'integer:min:1|max:100',
        ], []);
        return $this->success($this->service->list($data));
    }

    #[PostMapping('addAttraction')]
    public function addAttraction()
    {
        $data = $this->valid([
            'name' => 'required|string',
            'introTitle' => 'string',
            'intro' => 'string',
            'coverId' => 'string',
            'address' => 'string',
            'phone' => 'string',
            'openTime' => 'string',
            'closeTime' => 'string',
            'status' => 'integer',
        ], []);
        return $this->success($this->service->create($data));
    }

    #[GetMapping('deleteAttraction')]
    public function deleteAttraction()
    {
        $data = $this->valid(['id' => 'required|integer'], []);
        return $this->success($this->service->delete(intval($data['id'])));
    }

    #[PostMapping('updateAttraction')]
    public function updateAttraction()
    {
        $data = $this->valid([
            'id' => 'required|integer',
            'name' => 'string',
            'introTitle' => 'string',
            'intro' => 'string',
            'coverId' => 'string',
            'address' => 'string',
            'phone' => 'string',
            'openTime' => 'string',
            'closeTime' => 'string',
            'status' => 'integer',
        ], []);
        return $this->success($this->service->update(intval($data['id']), $data));
    }

    #[GetMapping('detailAttraction')]
    public function detailAttraction()
    {
        $data = $this->valid(['id' => 'required|integer'], []);
        return $this->success($this->service->get(intval($data['id'])));
    }
}